home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / fractals / apfelkiste / apfelkiste2.0 / source / apfelkiste2.0src.lzh / Fixpoint.c < prev    next >
C/C++ Source or Header  |  1991-10-23  |  3KB  |  119 lines

  1. /************************************************************************/
  2. /* Fixpoint.c                                */
  3. /*                                    */
  4. /* Fix-point version of the mandelbrot genrator. See Float.c for math    */
  5. /* details. The UPPER CASE variables contain the FXP counterparts of    */
  6. /* the ones written in lower case.                    */
  7. /************************************************************************/
  8.  
  9. #include <proto/intuition.h>
  10. #include <proto/graphics.h>
  11. #include <mffp.h>
  12. #include <math.h>
  13.  
  14. /* -------------------------------------------------------------------- */
  15. /* "Zwei hoch 24" is german for "two, powered by 24" or 2**24.        */
  16. /* Forgive me, I haven't had the patience to translate all variable    */
  17. /* names to english.                            */
  18. /* -------------------------------------------------------------------- */
  19.  
  20. #define ZWEI_HOCH_24    16777216.0
  21.  
  22. /* -------------------------------------------------------------------- */
  23. /* import externaly defined objects                    */
  24. /* -------------------------------------------------------------------- */
  25.  
  26. extern struct RastPort    *rp;
  27. extern struct GfxBase    *GfxBase;
  28.  
  29. extern long __asm Iter_FXP(register __d1 long r, register __d2 long i,register __a2 long divergenz);
  30.  
  31. extern short __regargs Test(long xx1, long yy1, long xx2, long yy2);
  32.  
  33. /* -------------------------------------------------------------------- */
  34.  
  35. long    DIVERGENZ, RMIN, IMIN, DX, DY;
  36. short    MAXITER;
  37.  
  38. void __regargs Apfel_FXP(long x1, long y1, long x2, long y2)
  39. {
  40.     long xneu, yneu, help1, help2;
  41.  
  42.     if ( x2 - x1 > 1 && y2 - y1 > 1 ) {
  43.         if ( Test(x1, y1, x2, y2) ) {
  44.             SetAPen(rp, ReadPixel(rp, x1, y1));
  45.             RectFill(rp, x1+1, y1+1, x2-1, y2-1);
  46.         }
  47.         else {
  48.             if ( x2 - x1 + y1 > y2 ) {
  49.                 xneu    = (x1 + x2) >> 1;
  50.                 help1    = RMIN + xneu * DX;
  51.                 help2    = (y1 + 1) * DY + IMIN;
  52.                 for ( yneu = y1 + 1; yneu < y2; yneu++ ) {
  53.                     SetAPen(rp, Iter_FXP(help1, help2, DIVERGENZ));
  54.                     WritePixel(rp, xneu, yneu);
  55.                     help2 += DY;
  56.                 }
  57.                 Apfel_FXP(x1, y1, xneu, y2);
  58.                 Apfel_FXP(xneu, y1, x2, y2);
  59.             }
  60.             else {
  61.                 yneu    = (y1 + y2) >> 1;
  62.                 help1    = IMIN + yneu * DY;
  63.                 help2    = (x1 + 1) * DX + RMIN;
  64.                 for ( xneu = x1 + 1; xneu < x2; xneu++ ) {
  65.                     SetAPen(rp, Iter_FXP(help2, help1, DIVERGENZ));
  66.                     WritePixel(rp, xneu, yneu);
  67.                     help2 += DX;
  68.                 }
  69.                 Apfel_FXP(x1, y1, x2, yneu);
  70.                 Apfel_FXP(x1, yneu, x2, y2);
  71.             }
  72.         }
  73.     }
  74. }
  75.  
  76. /* -------------------------------------------------------------------- */
  77. /* Some initializations are needed for the FXP version.         */
  78. /* -------------------------------------------------------------------- */
  79.  
  80. void FixPoint(double rmin, double rmax, double imin, double imax, double dx, double dy,
  81.         int maxiter, double divergenz, int gx, int gy, int depth)
  82. {
  83.     long    help1, help2, help3, help4;
  84.     long    x, y;
  85.  
  86.     DIVERGENZ    = divergenz    * ZWEI_HOCH_24;
  87.     RMIN        = rmin        * ZWEI_HOCH_24;
  88.     IMIN        = imin        * ZWEI_HOCH_24;
  89.     DX        = dx        * ZWEI_HOCH_24;
  90.     DY        = dy        * ZWEI_HOCH_24;
  91.     MAXITER        = maxiter - 1;
  92.  
  93.     help1        = RMIN;
  94.     help4        = gy - 1;
  95.     help3        = imax * ZWEI_HOCH_24;
  96.  
  97.     for ( x = 0; x < gx; x++ ) {
  98.         SetAPen(rp, Iter_FXP(help1, IMIN, DIVERGENZ));
  99.         WritePixel(rp, x, 0);
  100.         SetAPen(rp, Iter_FXP(help1, help3, DIVERGENZ));
  101.         WritePixel(rp, x, help4);
  102.         help1 += DX;
  103.     }
  104.  
  105.     help1        = IMIN;
  106.     help2        = gx - 1;
  107.     help3        = rmax * ZWEI_HOCH_24;
  108.  
  109.     for ( y = 0; y < gy; y++ ) {
  110.         SetAPen(rp, Iter_FXP(RMIN, help1, DIVERGENZ));
  111.         WritePixel(rp, 0, y);
  112.         SetAPen(rp, Iter_FXP(help3, help1, DIVERGENZ));
  113.         WritePixel(rp, help2, y);
  114.         help1 += DY;
  115.     }
  116.  
  117.     Apfel_FXP(0, 0, help2, help4);
  118. }
  119.